home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Drivers / ghostHPDJ / pp0cat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-23  |  835 b   |  43 lines

  1. /* Copyright 1994 Steve Ludtke (steve@ion.rice.edu) */
  2. /* pp0cat.c this program gets around the bug in the NeXT parallel port */
  3. /* driver by re write()ing data as necessary */
  4. /* Many thanks to Federico Heinz for telling me about this bug */
  5.  
  6. #include <stdio.h>
  7. #include <sys/file.h>
  8.  
  9. main(int argc, char *argv[])
  10. {
  11. int r,w,i,std=0;
  12. FILE *in;
  13. int out;
  14. char data[4096],*ptr;
  15.  
  16. if (argc==1) { argc++; std=1; }
  17.  
  18. /* if we have >1 arg */
  19. for (i=1; i<argc; i++) {
  20.     if (std && i==1) in=stdin;
  21.     else {
  22.         in=fopen(argv[i],"r");
  23.         if (in==NULL) { printf("Cannot open %s\n",argv[i]); continue; }
  24.     }
  25.  
  26.     /* write the file(s) */
  27.     out=open("/dev/pp0",O_WRONLY,0);
  28.  
  29.     while ((r=fread(data,1,4096,in))>0) {
  30.         ptr=data;
  31.         w=0;
  32.         while (r>0) {
  33.             w=write(out,ptr,r);
  34.             if (w<r) sleep(5);
  35.             r-=w;
  36.             ptr+=w;
  37.         }
  38.     }
  39.     close(out);
  40.     if (!std) fclose(in);
  41. }
  42. }
  43.